"""
API数据模型定义
"""

from datetime import datetime
from typing import Dict, List, Optional, Any
from pydantic import BaseModel


class SessionInfo(BaseModel):
    """Session信息模型"""
    id: str
    created_at: datetime
    usage_count: int
    max_usage_count: int
    error_score: float
    max_error_score: float
    is_usable: bool
    is_blocked: bool
    is_expired: bool
    expires_at: datetime
    user_data: Dict[str, Any]


class BrowserInfo(BaseModel):
    """浏览器信息模型"""
    id: str
    name: str
    created_at: datetime
    is_active: bool
    last_used: Optional[datetime]
    page_count: int
    proxy_url: Optional[str]


class TaskRequest(BaseModel):
    """任务请求模型"""
    url: str
    session_id: Optional[str] = None
    browser_id: Optional[str] = None
    handler_type: str = "default"  # default, login, custom
    custom_data: Optional[Dict[str, Any]] = None


class TaskResult(BaseModel):
    """任务结果模型"""
    task_id: str
    url: str
    session_id: Optional[str]
    browser_id: Optional[str]
    status: str  # pending, running, completed, failed
    result: Optional[Dict[str, Any]]
    error: Optional[str]
    created_at: datetime
    completed_at: Optional[datetime] 